package com.haoziqi.chapter_07;

import org.apache.flink.api.common.eventtime.WatermarkStrategy;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.api.java.tuple.Tuple3;
import org.apache.flink.streaming.api.datastream.KeyedStream;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * description
 * created by A on 2021/3/11
 */
public class Demo1 {
    public static void main(String[] args) {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);

        //
        SingleOutputStreamOperator<Tuple2<String, Long>> ds1 = env
                .fromElements(
                        Tuple2.of("a", 1L),
                        Tuple2.of("a", 2L),
                        Tuple2.of("b", 3L),
                        Tuple2.of("c", 4L),
                        Tuple2.of("d", 5L)
                )
                .assignTimestampsAndWatermarks(
                        WatermarkStrategy
                                .<Tuple2<String, Long>>forMonotonousTimestamps()
                                .withTimestampAssigner((value, ts) -> value.f1 * 1000L)
                );

        SingleOutputStreamOperator<Tuple3<String, Long, Integer>> ds2 = env
                .fromElements(
                        Tuple3.of("a", 1L, 1),
                        Tuple3.of("a", 3L, 1),
                        Tuple3.of("b", 2L, 1),
                        Tuple3.of("b", 13L, 1),
                        Tuple3.of("c", 14L, 1),
                        Tuple3.of("d", 15L, 1)
                )
                .assignTimestampsAndWatermarks(
                        WatermarkStrategy
                                .<Tuple3<String, Long, Integer>>forMonotonousTimestamps()
                                .withTimestampAssigner((value, ts) -> value.f1 * 1000L)
                );

        // TODO Interval Join
        KeyedStream<Tuple2<String, Long>, String> ks1 = ds1.keyBy(r -> r.f0);
        KeyedStream<Tuple3<String, Long, Integer>, String> ks2 = ds2.keyBy(r -> r.f0);


    }
}
